<template>

	<Cascader v-model="valueArray" :data="newSbType" :load-data="loadData" change-on-select @on-change="changeData" ref="click"
	 trigger="hover"  @on-visible-change='open'></Cascader>

</template>

<script>
	import cityFormApi from "@/api/base_sys/gcDispenser.js";
	import moment from "moment";
	import {
		Message
	} from "iview";
	export default {
		name: "cityForm",
		data() {
			return {
				value: true,
				indeterminate: false,
				checkAll: false,
				newSbType: [

				],
				
				valueArray: [],
				newObject: {
					provid: '',
					cityid: '',
					distid: '',
					strt: '',
					commid: '',
					comminid: ''

				},
				selectedData:'',
				// 弹出层数据
				modal: {
					cityForm: {
						type: "create", // create 新建，update 修改
						title: "新建",
						formData: {

						},
					}
				},

			};
		},
		methods: {
			//城市级联
			getProvince(data) {
				cityFormApi.getDown(data).then(res => {
					/* console.log(res)
					console.log('1') */
					let that = this;
					let province = res.data;
					for (let i = 0; i < province.length; i++) {
						let wzpz = province[i];
						wzpz.value = wzpz.id;
						wzpz.label = wzpz.name;
						wzpz.loading = false;
						wzpz.children = [];
						that.newSbType.push(wzpz);
					}
				})
			},

			loadData(item, callback) {
				item.loading = true;
				cityFormApi.getDown(item.id).then(res => {
					if (res.data == '') {
						let wzpz = {};
						wzpz.value = '';
						wzpz.label = '当前暂无数据';
						// wzpz.disabled = true ;
						wzpz.loading = false;
						// item.children.push(wzpz);
					} else {
						for (let city of res.data) {
							let wzpz = city;
							cityFormApi.getDown(wzpz.id).then(rs => {
								if (rs.data != '') {
									wzpz.value = wzpz.id;
									wzpz.label = wzpz.name;
									wzpz.loading = false;
									wzpz.children = [];
								} else {
									wzpz.value = wzpz.id;
									wzpz.label = wzpz.name;
								}
							})

							item.children.push(wzpz);
						}

						item.loading = false;
						callback();
					}

				})


			},
			changeData(value, selectedData) {
				// console.log(selectedData)
				this.selectedData=selectedData;
				// console.log(value);
				this.newObject.provid = value[0] || '';
				this.newObject.cityid = value[1] || '';
				this.newObject.distid = value[2] || '';
				this.newObject.strt = value[3] || '';
				this.newObject.commid = value[4] || '';
				this.newObject.comminid = value[5] || '';
				this.$emit('ProvinceData', this.newObject);
				// console.log(this.newObject)
			},
			open(Boolean){
				// console.log(Boolean)
				const that=this
				that.newSbType=[]
				if(Boolean==true){
					this.getProvince('1');
				}
			}
		},



		created() {
			// 
		}
	};
</script>

<style>

</style>
